<template>
  <div class="settings web">
    <div class="cont">
      <div class="nav">
        <el-menu :default-active="activeMenu" router @select="handleSelect" text-color="#333"
          class="el-menu-vertical-demo">
          <!-- <el-menu-item index="notice">
            <span slot="title">
              <el-icon>
                <DataBoard />
              </el-icon>
              公告
            </span>
          </el-menu-item> -->

          <el-menu-item index="account">
            <span slot="title">
              <el-icon>
                <Postcard />
              </el-icon>
              账号管理
            </span>
          </el-menu-item>

          <el-menu-item index="log">
            <span slot="title">
              <el-icon>
                <Reading />
              </el-icon>
              系统日志
            </span>
          </el-menu-item>

          <!-- <el-menu-item index="watermark">
            <span slot="title">
              <el-icon>
                <Setting />
              </el-icon>
              水印设置
            </span>
          </el-menu-item> -->
        </el-menu>
      </div>
      <div class="content">
        <div class="content-crumbs">
          <h3>{{ currentRoute }}</h3>
          <!-- <el-breadcrumb separator="/">
            <el-breadcrumb-item>{{ currentRoute }}</el-breadcrumb-item>
          </el-breadcrumb> -->
        </div>
        <div class="content-box">
          <router-view></router-view>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { DataBoard, Postcard, Reading, Setting } from '@element-plus/icons-vue'
const router = useRouter()
const route = useRoute()
const activeMenu = ref('')
const currentRoute = ref('')
// 处理菜单选择
const handleSelect = (key) => {
  router.push(`/admin/settings/${key}`);
}
// 计算当前激活的菜单项
const getActiveMenu = () => {
  // 获取当前路由的完整路径
  const currentPath = route.path;
  // 匹配子路由的路径片段
  const subRoutePath = currentPath.split('/').pop();
  // 面包屑
  currentRoute.value = route.meta.key
  // 优先匹配子路由名称（若路由配置了 name）
  // 若未配置 name，回退到路径片段
  return subRoutePath || 'account';
};
// 监听路由变化，实时更新 activeMenu
watch(() => route.path, (newPath) => {
  activeMenu.value = getActiveMenu();
}, { immediate: true }); // 初始化时立即执行一次
</script>

<style lang="less" scoped>
@import "@/assets/scss/web.scss";

.settings {
  .nav {
    height: 100%;
    background-color: #fff;
    width: 200px;
    padding-top: 20px;
    border-right: 1px solid #dcdfe6;

    .el-menu-vertical-demo {
      height: 100%;
      background-color: #fff;
      border: none;
    }

    .el-menu-item {
      font-size: 14px;
      height: 40px;
    }

    .el-menu-item.is-active {
      color: #333;
      background-color: #ecf5ff;
    }
  }

  .content {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 0 20px 20px 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    .content-crumbs {
      height: 40px;
      line-height: 40px;
      background-color: #fff;
      width: 100%;
      border-bottom: 1px solid #dcdfe6;

      h3 {
        margin-left: 20px;
      }
    }

    .content-box {
      flex: 1;
      background-color: #fff;
      width: calc(100% - 20px);
      box-sizing: border-box;
      margin: 10px;
      border-radius: 8px;
      overflow: auto;
      padding: 10px;
    }
  }

}
</style>